library(tidyverse)
getwd()
# Read in raw survey data
source("read raw data.R") # this create 'survey_data.R, a selection of the raw data plus information received from Kantar
# Read in raw survey data
source("Scripts/read raw data.R") # this create 'survey_data.R, a selection of the raw data plus information received from Kantar
# construct measured variables from raw data
source("Scripts/Study 1 Data Manipulation.R")
# make figure 1 for paper
source("Scripts/descriptives_dv_plot.R")
# conduct analysis and plot figures for study 1
source("Scripts/Study 1 Data Analysis Empathy and Party Sympathy.R")
# To make Figure 1
source("Scripts/descriptives_dv_plot.R")
# This scripts reads in the raw data and adds measured variables
source("Scripts/Study 2 data manipulation.R")
# This script analyzes the experimental data (study 2)
source("Scripts/Study 2 Data Analysis Empathy, Censorship and Schadenfreude.R")
# This scripts reads in the raw data and adds measured variables
source("Scripts/Study 2 data manipulation.R")
# This script analyzes the experimental data (study 2)
source("Scripts/Study 2 Data Analysis Empathy, Censorship and Schadenfreude.R")
load("Data/study_2.RData") #name = data
data$Condition[data$protestIn_speakerOut==1] <- 'Outgroup Speaker'
# ignore warning
data$Condition[data$protestIn_speakerOut==0] <- 'Ingroup Speaker'
#----Descriptive Statistics Tables-----
data_descriptives <- subset(data, select = c(empathic_concern, perspective_taking, protestIn_speakerOut, protestIn_speakerOut_IncCenter,
censorship, punishment, sympathy,schadenfreude
))
data_descriptives <- subset(data[data$protestIn_speakerOut==1,], select = c(empathic_concern, perspective_taking,
censorship, punishment, sympathy,schadenfreude,
left_right_placement_1, Perceived_Realism01, ClosenessProtestGroup_01))
# Estimate interaction effects ------------------------------
hypo3a <- lm(censorship ~ empathic_concern + as.factor(Condition) + empathic_concern*as.factor(Condition), data = data)
hypo4a <- lm(schadenfreude ~ empathic_concern + as.factor(Condition) + empathic_concern*as.factor(Condition), data = data)
extra1a <- lm(punishment ~ empathic_concern + as.factor(Condition) + empathic_concern*as.factor(Condition), data = data)
extra2a <- lm(sympathy ~ empathic_concern + as.factor(Condition) + empathic_concern*as.factor(Condition), data = data)
(mylista <- list(empathic_concern=seq(0,1,by=0.1),Condition=c('Ingroup Speaker','Outgroup Speaker')))
emcontcat  <- emmeans(hypo3a, ~ empathic_concern*Condition, at=mylista)
contrast3a <- contrast(emcontcat, "revpairwise",by="empathic_concern")
emcontcat  <- emmeans(hypo4a, ~ empathic_concern*Condition, at=mylista)
contrast4a <- contrast(emcontcat, "revpairwise",by="empathic_concern")
emcontcat  <- emmeans(extra1a, ~ empathic_concern*Condition, at=mylista)
contrast1a <- contrast(emcontcat, "revpairwise",by="empathic_concern")
emcontcat  <- emmeans(extra2a, ~ empathic_concern*Condition, at=mylista)
contrast2a <- contrast(emcontcat, "revpairwise",by="empathic_concern")
hypo3b <- lm(censorship ~ perspective_taking*Condition, data = data)
hypo4b <- lm(schadenfreude ~ perspective_taking*Condition, data = data)
extra1b <- lm(punishment ~ perspective_taking*Condition, data = data)
extra2b <- lm(sympathy ~ perspective_taking*Condition, data = data)
(mylistb <- list(perspective_taking=seq(0,1,by=0.1),Condition=c('Ingroup Speaker','Outgroup Speaker')))
emcontcat  <- emmeans(hypo3b, ~ perspective_taking*Condition, at=mylistb)
contrast3b <- contrast(emcontcat, "revpairwise",by="perspective_taking")
emcontcat  <- emmeans(hypo4b, ~ perspective_taking*Condition, at=mylistb)
contrast4b <- contrast(emcontcat, "revpairwise",by="perspective_taking")
emcontcat  <- emmeans(extra1b, ~ perspective_taking*Condition, at=mylistb)
contrast1b <- contrast(emcontcat, "revpairwise",by="perspective_taking")
emcontcat  <- emmeans(extra2b, ~ perspective_taking*Condition, at=mylistb)
contrast2b <- contrast(emcontcat, "revpairwise",by="perspective_taking")
stargazer(hypo3a, extra1a, extra2a, hypo4a) # Table B4
stargazer(hypo3b, extra1b, extra2b, hypo4b) # Table B5
# Previous study: SCK and make Figure 3 -------------
load("Data/simas_clifford_kirkland_study2_replication.RData")
colnames(table)[3:9] <- c("punishment", "sympathy", "schadenfreude", "Condition", "empathic_concern", "perspective_taking", "censorship")
table$Condition <- ifelse(table$Condition==1, "Outgroup Speaker",
"Ingroup Speaker")
sck_hypo3a <- lm(censorship ~ empathic_concern + as.factor(Condition) + empathic_concern*as.factor(Condition), data = table)
sck_hypo4a <- lm(schadenfreude ~ empathic_concern + as.factor(Condition) + empathic_concern*as.factor(Condition), data = table)
sck_extra1a <- lm(punishment ~ empathic_concern + as.factor(Condition) + empathic_concern*as.factor(Condition), data = table)
sck_extra2a <- lm(sympathy ~ empathic_concern + as.factor(Condition) + empathic_concern*as.factor(Condition), data = table)
(mylista <- list(empathic_concern=seq(0,1,by=0.1),Condition=c('Ingroup Speaker','Outgroup Speaker')))
emcontcat  <- emmeans(sck_hypo3a, ~ empathic_concern*Condition, at=mylista)
sck_contrast3a <- contrast(emcontcat, "revpairwise",by="empathic_concern")
emcontcat  <- emmeans(sck_hypo4a, ~ empathic_concern*Condition, at=mylista)
sck_contrast4a <- contrast(emcontcat, "revpairwise",by="empathic_concern")
emcontcat  <- emmeans(sck_extra1a, ~ empathic_concern*Condition, at=mylista)
sck_contrast1a <- contrast(emcontcat, "revpairwise",by="empathic_concern")
emcontcat  <- emmeans(sck_extra2a, ~ empathic_concern*Condition, at=mylista)
sck_contrast2a <- contrast(emcontcat, "revpairwise",by="empathic_concern")
sck_hypo3b <- lm(censorship ~ perspective_taking*Condition, data = table)
sck_hypo4b <- lm(schadenfreude ~ perspective_taking*Condition, data = table)
sck_extra1b <- lm(punishment ~ perspective_taking*Condition, data = table)
sck_extra2b <- lm(sympathy ~ perspective_taking*Condition, data = table)
(mylistb <- list(perspective_taking=seq(0,1,by=0.1),Condition=c('Ingroup Speaker','Outgroup Speaker')))
emcontcat  <- emmeans(sck_hypo3b, ~ perspective_taking*Condition, at=mylistb)
sck_contrast3b <- contrast(emcontcat, "revpairwise",by="perspective_taking")
emcontcat  <- emmeans(sck_hypo4b, ~ perspective_taking*Condition, at=mylistb)
sck_contrast4b <- contrast(emcontcat, "revpairwise",by="perspective_taking")
emcontcat  <- emmeans(sck_extra1b, ~ perspective_taking*Condition, at=mylistb)
sck_contrast1b <- contrast(emcontcat, "revpairwise",by="perspective_taking")
emcontcat  <- emmeans(sck_extra2b, ~ perspective_taking*Condition, at=mylistb)
sck_contrast2b <- contrast(emcontcat, "revpairwise",by="perspective_taking")
output.list <- c("contrast1a", "contrast2a", "contrast3a", "contrast4a",
"contrast1b", "contrast2b", "contrast3b", "contrast4b",
"sck_contrast1a", "sck_contrast2a", "sck_contrast3a", "sck_contrast4a",
"sck_contrast1b", "sck_contrast2b", "sck_contrast3b", "sck_contrast4b")
output <- lapply(output.list, function(x){
model <- x
x <- get(x)
x <- data.frame(x)
x$model <- model
return(x)}
)
output_ec <- do.call("rbind", output[c(1:4,9:12)])
output_pt <- do.call("rbind", output[c(5:8,13:16)])
output_ec$analysis <- ifelse(str_detect(output_ec$model, "sck")==TRUE, "SCK", "GSR")
output_ec$dv <- ifelse(str_detect(output_ec$model,"1")==TRUE, "Punishment",
ifelse(str_detect(output_ec$model,"2")==TRUE, "Sympathy",
ifelse(str_detect(output_ec$model,"3")==TRUE, "Censorship","Schadenfreude")))
output_ec$lo <- output_ec$estimate - 1.96*output_ec$SE
output_ec$hi <- output_ec$estimate + 1.96*output_ec$SE
output_pt$analysis <- ifelse(str_detect(output_pt$model, "sck")==TRUE, "SCK", "GSR")
output_pt$dv <- ifelse(str_detect(output_pt$model,"1")==TRUE, "Punishment",
ifelse(str_detect(output_pt$model,"2")==TRUE, "Sympathy",
ifelse(str_detect(output_pt$model,"3")==TRUE, "Censorship","Schadenfreude")))
output_pt$lo <- output_pt$estimate - 1.96*output_pt$SE
output_pt$hi <- output_pt$estimate + 1.96*output_pt$SE
cbp2 <- c("#000000", "#E69F00", "#56B4E9", "#009E73",
"#F0E442", "#0072B2", "#D55E00", "#CC79A7")
ec <- ggplot(output_ec, aes(x=empathic_concern, y=estimate, fill=analysis)) +
geom_line() +
geom_ribbon(aes(ymin=lo, ymax=hi), alpha=.5) +
facet_wrap(~dv, nrow=2, scales="free") +
geom_hline(yintercept=0, linetype="dashed") +
scale_fill_manual(values = cbp2) +
xlab("Empathic Concern")+
theme(legend.title=element_blank())
pt <- ggplot(output_pt, aes(x=perspective_taking, y=estimate, fill=analysis)) +
geom_line() +
geom_ribbon(aes(ymin=lo, ymax=hi), alpha=.5) +
facet_wrap(~dv, nrow=2, scales="free") +
geom_hline(yintercept=0, linetype="dashed") +
scale_fill_manual(values = cbp2) +
xlab("Perspective taking") +
theme(legend.title=element_blank())
ec_pt_plot <- ggpubr::ggarrange(ec, pt, nrow=2, common.legend=TRUE, legend="bottom")
# Make smaller version for main paper
selection <- c("Censorship", "Schadenfreude")
colnames(output_ec)[2] <- "z"
colnames(output_pt)[2] <- "z"
output_ec$z.var <- "EC"
output_pt$z.var <- "PT"
output_ec_pt <- dplyr::bind_rows(output_ec[output_ec$dv%in%selection,], output_pt[output_pt$dv%in%selection,])
ec_pt <- ggplot(output_ec_pt, aes(x=z, y=estimate, fill=analysis)) +
geom_line() +
geom_ribbon(aes(ymin=lo, ymax=hi), alpha=.5) +
facet_grid(z.var~dv, scales="free") +
geom_hline(yintercept=0, linetype="dashed") +
scale_fill_manual(values = cbp2) +
xlab("Moderator") +
theme(legend.title=element_blank(),
legend.position="bottom")
ggsave(ec_pt,file="Tables and Figures/ec_pt_plot_small.jpg", dpi=1000, height=3, width=3)
ggsave(ec_pt,file="Tables and Figures/ec_pt_plot_small.jpg", dpi=1000, height=6, width=4)
ggsave(fig.effects, file="Tables and Figures/fig_effects.jpg", dpi=1000, width=6, height=4)
rm(list=ls())
# Read in raw survey data
source("Scripts/read raw data.R") # this create 'survey_data.R, a selection of the raw data plus information received from Kantar
# construct measured variables from raw data
source("Scripts/Study 1 Data Manipulation.R")
# conduct analysis and plot figures for study 1
source("Scripts/Study 1 Data Analysis Empathy and Party Sympathy.R")
# To make Figure 1
source("Scripts/descriptives_dv_plot.R")
# This scripts reads in the raw data and adds measured variables
source("Scripts/Study 2 data manipulation.R")
# This script analyzes the experimental data (study 2)
source("Scripts/Study 2 Data Analysis Empathy, Censorship and Schadenfreude.R")
rm(list=ls())
library(stargazer)
library(car)
library(emmeans)
library(ggplot2)
library(stringr)
load("Data/study_2.RData") #name = data
data$Condition[data$protestIn_speakerOut==1] <- 'Outgroup Speaker'
# ignore warning
data$Condition[data$protestIn_speakerOut==0] <- 'Ingroup Speaker'
data_descriptives <- subset(data, select = c(empathic_concern, perspective_taking, protestIn_speakerOut, protestIn_speakerOut_IncCenter,
censorship, punishment, sympathy,schadenfreude
))
stargazer(as.data.frame(data_descriptives), title="Descriptive Statistics for Full Sample", omit.summary.stat = c("p25", "p75"), out="Figures and Tables/study2_descriptives.tex")
stargazer(hypo3b, extra1b, extra2b, hypo4b) # Table B3
stargazer(hypo3a, extra1a, extra2a, hypo4a) # Table B2
# Estimate interaction effects ------------------------------
hypo3a <- lm(censorship ~ empathic_concern + as.factor(Condition) + empathic_concern*as.factor(Condition), data = data)
hypo4a <- lm(schadenfreude ~ empathic_concern + as.factor(Condition) + empathic_concern*as.factor(Condition), data = data)
extra1a <- lm(punishment ~ empathic_concern + as.factor(Condition) + empathic_concern*as.factor(Condition), data = data)
extra2a <- lm(sympathy ~ empathic_concern + as.factor(Condition) + empathic_concern*as.factor(Condition), data = data)
(mylista <- list(empathic_concern=seq(0,1,by=0.1),Condition=c('Ingroup Speaker','Outgroup Speaker')))
emcontcat  <- emmeans(hypo3a, ~ empathic_concern*Condition, at=mylista)
contrast3a <- contrast(emcontcat, "revpairwise",by="empathic_concern")
emcontcat  <- emmeans(hypo4a, ~ empathic_concern*Condition, at=mylista)
contrast4a <- contrast(emcontcat, "revpairwise",by="empathic_concern")
emcontcat  <- emmeans(extra1a, ~ empathic_concern*Condition, at=mylista)
contrast1a <- contrast(emcontcat, "revpairwise",by="empathic_concern")
emcontcat  <- emmeans(extra2a, ~ empathic_concern*Condition, at=mylista)
contrast2a <- contrast(emcontcat, "revpairwise",by="empathic_concern")
hypo3b <- lm(censorship ~ perspective_taking*Condition, data = data)
hypo4b <- lm(schadenfreude ~ perspective_taking*Condition, data = data)
extra1b <- lm(punishment ~ perspective_taking*Condition, data = data)
extra2b <- lm(sympathy ~ perspective_taking*Condition, data = data)
(mylistb <- list(perspective_taking=seq(0,1,by=0.1),Condition=c('Ingroup Speaker','Outgroup Speaker')))
emcontcat  <- emmeans(hypo3b, ~ perspective_taking*Condition, at=mylistb)
contrast3b <- contrast(emcontcat, "revpairwise",by="perspective_taking")
emcontcat  <- emmeans(hypo4b, ~ perspective_taking*Condition, at=mylistb)
contrast4b <- contrast(emcontcat, "revpairwise",by="perspective_taking")
emcontcat  <- emmeans(extra1b, ~ perspective_taking*Condition, at=mylistb)
contrast1b <- contrast(emcontcat, "revpairwise",by="perspective_taking")
emcontcat  <- emmeans(extra2b, ~ perspective_taking*Condition, at=mylistb)
contrast2b <- contrast(emcontcat, "revpairwise",by="perspective_taking")
stargazer(hypo3a, extra1a, extra2a, hypo4a) # Table B2
stargazer(hypo3b, extra1b, extra2b, hypo4b) # Table B3
#----Descriptive Statistics Tables-----
data_descriptives <- subset(data, select = c(empathic_concern, perspective_taking, protestIn_speakerOut, protestIn_speakerOut_IncCenter,
censorship, punishment, sympathy,schadenfreude
))
stargazer(as.data.frame(data_descriptives), title="Descriptive Statistics for Full Sample", omit.summary.stat = c("p25", "p75"), out="Figures and Tables/study2_descriptives.tex")
stargazer(as.data.frame(data_descriptives), title="Descriptive Statistics for Full Sample", omit.summary.stat = c("p25", "p75"), out="Tables and Figures/study2_descriptives.tex")
